package com.malty.common.util;

import org.springframework.util.DigestUtils;

import java.util.Map;

/**
 * @author malty
 */
public class SignUtil {
    public static String calculateSignKey(String privateKey, String paramStr) {
        String source = String.format("%s%s", privateKey, paramStr);
        return DigestUtils.md5DigestAsHex(source.getBytes());
    }

    public static String parameterHandler(Map<String, String> params) {
        StringBuilder builder = new StringBuilder();
        params.forEach((k, v) -> builder.append(k)
                .append("=")
                .append(v)
                .append("&"));
        builder.deleteCharAt(builder.length() - 1);
        return builder.toString();
    }
}
